using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DAL;

namespace BO.Admin
{
    public class Image_Helper
    {
        public static DataTable GetByNewsID(int News_ID)
        {
            DataTable dt;
            using (MainDB db = new MainDB())
            {
                dt = db.StoredProcedures.Image_GetByNewsID(News_ID);
            }
            if (!dt.Columns.Contains("PhotoLocation")) dt.Columns.Add("PhotoLocation");
            foreach (DataRow row in dt.Rows)
            {
                row["PhotoLocation"] = Utils.BuidImageUrl(row["Image_Url"].ToString());
            }
            return dt;
        }
        public static int Add(string Image_Url, int News_ID)
        {
            DataTable dt;
            using (MainDB db = new MainDB())
            {
                dt = db.StoredProcedures.Image_Add(Image_Url, News_ID);
            }
            int result = 0;
            try
            {
                result = Convert.ToInt32(dt.Rows[0][0]);
            }
            catch { }
            return result;
        }
        public static void Delete(int Image_ID)
        {
            using (MainDB db = new MainDB())
            {
                db.StoredProcedures.Image_Delete(Image_ID);
            }
        }
        public static void DeleteAll(int News_ID)
        {
            using (MainDB db = new MainDB())
            {
                db.StoredProcedures.Image_DeleteByNewsID(News_ID);
            }
        }
    }
}
